﻿#pragma once

#include "../../Server/MirDatabase/AccountInfo.h"
#include "../../Controls/FixedListViewControl/CustomFormControl.ListViewNF.h"
#include <string>
#include <vector>
#include <any>
#include <mutex>
#include "../../stringhelper.h"

using namespace Server::MirDatabase;
using namespace Server::MirEnvir;

namespace Server
{
    class AccountInfoForm : public System::Windows::Forms::Form
    {
    private:
        std::vector<AccountInfo*> _selectedAccountInfos;

    public:
        virtual ~AccountInfoForm()
        {
            delete components;
            delete CreateButton;
            delete AccountInfoListView;
            delete indexHeader;
            delete accountIDHeader;
            delete label1;
            delete FilterTextBox;
            delete passwordHeader;
            delete userNameHeader;
            delete bannedHeader;
            delete banReasonHeader;
            delete expiryDateHeader;
            delete RefreshButton;
            delete AccountInfoPanel;
            delete AnswerTextBox;
            delete label7;
            delete QuestionTextBox;
            delete label6;
            delete BirthDateTextBox;
            delete label5;
            delete UserNameTextBox;
            delete label4;
            delete PasswordTextBox;
            delete label3;
            delete AccountIDTextBox;
            delete label2;
            delete EMailTextBox;
            delete label8;
            delete LastDateTextBox;
            delete label11;
            delete LastIPTextBox;
            delete label12;
            delete CreationDateTextBox;
            delete label9;
            delete CreationIPTextBox;
            delete label10;
            delete ExpiryDateTextBox;
            delete label14;
            delete BanReasonTextBox;
            delete label13;
            delete BannedCheckBox;
            delete PermBanButton;
            delete WeekBanButton;
            delete DayBanButton;
            delete AdminCheckBox;
            delete adminHeader;
            delete label15;
            delete FilterPlayerTextBox;
            delete MatchFilterCheckBox;
            delete WipeCharButton;
        }

        AccountInfoForm();

        AccountInfoForm(const std::string &accountId, bool match = false);

    private:
        void Setup();

        void AutoResize();

        void Update(ListViewItem *ListItem, AccountInfo *account);

        ListViewItem *CreateListView(AccountInfo *account);

    public:
        void RefreshInterface();

    private:
        void AccountInfoListView_SelectedIndexChanged(std::any sender, EventArgs *e);

        void CreateButton_Click(std::any sender, EventArgs *e);

        void AccountIDTextBox_TextChanged(std::any sender, EventArgs *e);

        void PasswordTextBox_TextChanged(std::any sender, EventArgs *e);

        void UserNameTextBox_TextChanged(std::any sender, EventArgs *e);

        void BirthDateTextBox_TextChanged(std::any sender, EventArgs *e);

        void QuestionTextBox_TextChanged(std::any sender, EventArgs *e);

        void AnswerTextBox_TextChanged(std::any sender, EventArgs *e);

        void EMailTextBox_TextChanged(std::any sender, EventArgs *e);

        void DayBanButton_Click(std::any sender, EventArgs *e);

        void WeekBanButton_Click(std::any sender, EventArgs *e);

        void PermBanButton_Click(std::any sender, EventArgs *e);

        void BannedCheckBox_CheckedChanged(std::any sender, EventArgs *e);

        void BanReasonTextBox_TextChanged(std::any sender, EventArgs *e);

        void ExpiryDateTextBox_TextChanged(std::any sender, EventArgs *e);

        void RefreshButton_Click(std::any sender, EventArgs *e);

        void AccountInfoForm_FormClosed(std::any sender, FormClosedEventArgs *e);

        void AdminCheckBox_CheckedChanged(std::any sender, EventArgs *e);

        void WipeCharButton_Click(std::any sender, EventArgs *e);


        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::IContainer *components = nullptr;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected:
        void Dispose(bool disposing) override;

        #pragma region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
    private:
        void InitializeComponent();

        #pragma endregion

        System::Windows::Forms::Button *CreateButton;
        CustomFormControl::ListViewNF *AccountInfoListView;
        System::Windows::Forms::ColumnHeader *indexHeader;
        System::Windows::Forms::ColumnHeader *accountIDHeader;
        System::Windows::Forms::Label *label1;
        System::Windows::Forms::TextBox *FilterTextBox;
        System::Windows::Forms::ColumnHeader *passwordHeader;
        System::Windows::Forms::ColumnHeader *userNameHeader;
        System::Windows::Forms::ColumnHeader *bannedHeader;
        System::Windows::Forms::ColumnHeader *banReasonHeader;
        System::Windows::Forms::ColumnHeader *expiryDateHeader;
        System::Windows::Forms::Button *RefreshButton;
        System::Windows::Forms::Panel *AccountInfoPanel;
        System::Windows::Forms::TextBox *AnswerTextBox;
        System::Windows::Forms::Label *label7;
        System::Windows::Forms::TextBox *QuestionTextBox;
        System::Windows::Forms::Label *label6;
        System::Windows::Forms::TextBox *BirthDateTextBox;
        System::Windows::Forms::Label *label5;
        System::Windows::Forms::TextBox *UserNameTextBox;
        System::Windows::Forms::Label *label4;
        System::Windows::Forms::TextBox *PasswordTextBox;
        System::Windows::Forms::Label *label3;
        System::Windows::Forms::TextBox *AccountIDTextBox;
        System::Windows::Forms::Label *label2;
        System::Windows::Forms::TextBox *EMailTextBox;
        System::Windows::Forms::Label *label8;
        System::Windows::Forms::TextBox *LastDateTextBox;
        System::Windows::Forms::Label *label11;
        System::Windows::Forms::TextBox *LastIPTextBox;
        System::Windows::Forms::Label *label12;
        System::Windows::Forms::TextBox *CreationDateTextBox;
        System::Windows::Forms::Label *label9;
        System::Windows::Forms::TextBox *CreationIPTextBox;
        System::Windows::Forms::Label *label10;
        System::Windows::Forms::TextBox *ExpiryDateTextBox;
        System::Windows::Forms::Label *label14;
        System::Windows::Forms::TextBox *BanReasonTextBox;
        System::Windows::Forms::Label *label13;
        System::Windows::Forms::CheckBox *BannedCheckBox;
        System::Windows::Forms::Button *PermBanButton;
        System::Windows::Forms::Button *WeekBanButton;
        System::Windows::Forms::Button *DayBanButton;
        System::Windows::Forms::CheckBox *AdminCheckBox;
        System::Windows::Forms::ColumnHeader *adminHeader;
        System::Windows::Forms::Label *label15;
        System::Windows::Forms::TextBox *FilterPlayerTextBox;
        System::Windows::Forms::CheckBox *MatchFilterCheckBox;
        System::Windows::Forms::Button *WipeCharButton;
    };
}
